$(function () {


    //跳转菜单添加页面
    $("#menu_add").click(function () {
        window.location.href="doAddMenuPage";
    });


    //跳转菜单编辑页面
    $("#menu_editor").click(function () {
        var menuCode = $("#menu_code").val();
        if (menuCode != null || "" != menuCode){
            window.location.href="doEditor/"+menuCode;
        }
    });




    $("#menu_submit").click(function(){
        var menuname = $("#menuname").val();
        var menucode = $("#menucode").val();
        var menuremark = $("#menuremark").val();
        var parentcode = $("#parentcode").val();
        var mydata = '{"menuName":"' + menuname + '","menuCode":"'  + menucode + '","menuRemark":"'+menuremark+'","parentCode":"'+parentcode+'"}';
        $.ajax({
            url: "addMenu",
            data: mydata,
            type: "post",
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    window.location.href = "menuList";
                } else {
                    alert(data["retMsg"]);
                }
            }
        });

    });

    //删除角色
    $("#menu_delete").click(function () {
        var menuCode = $("#menu_code").val();
        swal({
            title: "您确定要删除这条信息吗",
            text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            timer:2000,
            closeOnConfirm: false
        }, function () {
            //调用删除
            var mydata = '{"menuCode":"' + menuCode + '"}';
            $.ajax({
                url: "delete",
                data: mydata,
                type: "post",
                contentType: "application/json",
                dataType:"json",
                success: function (data) {
                    if(data["retType"] == "0") {
                        swal("删除成功！", "您已经永久删除了这条信息。", "success");
                        $('#menuTableEvents').bootstrapTable('refresh');
                    } else {
                        alert(data["retMsg"]);
                    }
                }
            });

        });
    });


    //菜单列表
    $('#menuTableEvents').bootstrapTable({
        url: "list",
        search: false,
        pagination: true,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        pageSize:15,
        height:600,
        iconSize: 'outline',
        toolbar: '#exampleTableEventsToolbar',
        icons: {
            refresh: 'glyphicon-repeat',
            toggle: 'glyphicon-list-alt',
            columns: 'glyphicon-list'
        }
    });

    var $result = $('#examplebtTableEventsResult');
    //实例代码  暂留测试
    $('#menuTableEvents').on('all.bs.table', function(e, name, args) {
        console.log('Event:', name, ', data:', args);
    })
        .on('click-row.bs.table', function(e, row, $element) {
            console.log(row);
            $("#menu_code").val(row.menuCode);

        })
        .on('dbl-click-row.bs.table', function(e, row, $element) {
            $result.text('Event: dbl-click-row.bs.table');
        })
        .on('sort.bs.table', function(e, name, order) {
            $result.text('Event: sort.bs.table');
        })
        .on('check.bs.table', function(e, row) {
            $result.text(row);
        })
        .on('uncheck.bs.table', function(e, row) {
            $result.text('Event: uncheck.bs.table');
        })
        .on('check-all.bs.table', function(e) {
            $result.text('Event: check-all.bs.table');
        })
        .on('uncheck-all.bs.table', function(e) {
            $result.text('Event: uncheck-all.bs.table');
        })
        .on('load-success.bs.table', function(e, data) {
            $result.text('Event: load-success.bs.table');
        })
        .on('load-error.bs.table', function(e, status) {
            $result.text('Event: load-error.bs.table');
        })
        .on('column-switch.bs.table', function(e, field, checked) {
            $result.text('Event: column-switch.bs.table');
        })
        .on('page-change.bs.table', function(e, size, number) {
            $result.text('Event: page-change.bs.table');
        })
        .on('search.bs.table', function(e, text) {
            $result.text('Event: search.bs.table');
        });



});